package com.guigu.yuhao.controller;

import com.guigu.common.service.DesignModuleService;
import com.guigu.common.pojo.DModuleDetails;
import com.guigu.common.pojo.DesignModule;
import com.guigu.common.vo.SearchVo;
import com.guigu.common.vo.module_detailsVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/design")
public class DesignModuleController {
    @Resource
    private DesignModuleService designModuleService;

    @RequestMapping("/querydesignModule")
    @ResponseBody
    public SearchVo<DesignModule> designModule(@RequestBody SearchVo searchVo){

        return designModuleService.designModule(searchVo);
    }
    @RequestMapping("/qeuryall")
    @ResponseBody
    public SearchVo<DesignModule> qeuryall(@RequestBody SearchVo searchVo){

        return designModuleService.qeuryall(searchVo);
    }

    @RequestMapping("/updatedesignModule")
    @ResponseBody
    public SearchVo<DesignModule> updatedesignModule(@RequestBody SearchVo searchVo){

        return designModuleService.updatedesignModule(searchVo);
    }

    @RequestMapping("/updateMaterial")
    @ResponseBody
    public void updateMaterial(@RequestBody module_detailsVo module_details){
        module_details.setChanger("b002-1");
        module_details.setCheckTag("S001-0");
        List<DModuleDetails> dmoduleDetails = module_details.getDmoduleDetails();

        for (DModuleDetails d:dmoduleDetails){
            if(d.getId()==null){
                designModuleService.updateinsert(d);
            }else {
                designModuleService.updateMaterial(d);
            }
        }
        designModuleService.updateChangerandsetCheckTag(module_details);
    }
    @RequestMapping("/queryModule")
    @ResponseBody
    public List<DModuleDetails> queryModule(String id){
        int i=Integer.parseInt(id);
      return   designModuleService.queryDModule(i);
    }
    @RequestMapping("/deletedModuleDetails")
    @ResponseBody
    public void deletedModuleDetails(String id){
        System.out.println(id);
        int i=Integer.parseInt(id);
        designModuleService.deletedModuleDetails(i);
    }
    @RequestMapping("/material")
    @ResponseBody
    public void material(String id){

        designModuleService.material(id);
    }
    @RequestMapping("/notmaterial")
    @ResponseBody
    public void notmaterial(String id){

        designModuleService.notmaterial(id);
    }
}
